﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Server.model
{
	/// <summary>
	/// 类stock_day_count。
	/// </summary>
	[Serializable]
	public partial class stock_day_count
	{
		public stock_day_count()
		{}
		#region Model
		private int _id;
		private int _security_day_account_id;
		private DateTime _trade_date;
		private string _trade_type;
		private string _stock_name;
		private int _stock_code;
		private float _price;
		private int _num;
		private float _fee=.0f;
		private string _remark;
		/// <summary>
		/// auto_increment
		/// </summary>
		public int id
		{
			set{ _id=value;}
			get{return _id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int security_day_account_id
		{
			set{ _security_day_account_id=value;}
			get{return _security_day_account_id;}
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime trade_date
		{
			set{ _trade_date=value;}
			get{return _trade_date;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string trade_type
		{
			set{ _trade_type=value;}
			get{return _trade_type;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string stock_name
		{
			set{ _stock_name=value;}
			get{return _stock_name;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int stock_code
		{
			set{ _stock_code=value;}
			get{return _stock_code;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float price
		{
			set{ _price=value;}
			get{return _price;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int num
		{
			set{ _num=value;}
			get{return _num;}
		}
		/// <summary>
		/// 
		/// </summary>
		public float fee
		{
			set{ _fee=value;}
			get{return _fee;}
		}
		/// <summary>
		/// 
		/// </summary>
		public string remark
		{
			set{ _remark=value;}
			get{return _remark;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public stock_day_count(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select `id`,`security_day_account_id`,`trade_date`,`trade_type`,`stock_name`,`stock_code`,`price`,`num`,`fee`,`remark` ");
			strSql.Append(" FROM `stock_day_count` ");
			strSql.Append(" where `id`=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)};
			parameters[0].Value = id;

			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					this.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["security_day_account_id"]!=null && ds.Tables[0].Rows[0]["security_day_account_id"].ToString()!="")
				{
					this.security_day_account_id=int.Parse(ds.Tables[0].Rows[0]["security_day_account_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["trade_date"]!=null && ds.Tables[0].Rows[0]["trade_date"].ToString()!="")
				{
					this.trade_date=DateTime.Parse(ds.Tables[0].Rows[0]["trade_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["trade_type"]!=null)
				{
					this.trade_type=ds.Tables[0].Rows[0]["trade_type"].ToString();
				}
				if(ds.Tables[0].Rows[0]["stock_name"]!=null)
				{
					this.stock_name=ds.Tables[0].Rows[0]["stock_name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["stock_code"]!=null && ds.Tables[0].Rows[0]["stock_code"].ToString()!="")
				{
					this.stock_code=int.Parse(ds.Tables[0].Rows[0]["stock_code"].ToString());
				}
				if(ds.Tables[0].Rows[0]["price"]!=null && ds.Tables[0].Rows[0]["price"].ToString()!="")
				{
					this.price=float.Parse(ds.Tables[0].Rows[0]["price"].ToString());
				}
				if(ds.Tables[0].Rows[0]["num"]!=null && ds.Tables[0].Rows[0]["num"].ToString()!="")
				{
					this.num=int.Parse(ds.Tables[0].Rows[0]["num"].ToString());
				}
				if(ds.Tables[0].Rows[0]["fee"]!=null && ds.Tables[0].Rows[0]["fee"].ToString()!="")
				{
					this.fee=float.Parse(ds.Tables[0].Rows[0]["fee"].ToString());
				}
				if(ds.Tables[0].Rows[0]["remark"]!=null)
				{
					this.remark=ds.Tables[0].Rows[0]["remark"].ToString();
				}
			}
		}

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{

		return DbHelperMySQL.GetMaxID("`id`", "`stock_day_count`"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from `stock_day_count`");
			strSql.Append(" where `id`=@id ");

			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)};
			parameters[0].Value = id;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into `stock_day_count` (");
			strSql.Append("`security_day_account_id`,`trade_date`,`trade_type`,`stock_name`,`stock_code`,`price`,`num`,`fee`,`remark`)");
			strSql.Append(" values (");
			strSql.Append("@security_day_account_id,@trade_date,@trade_type,@stock_name,@stock_code,@price,@num,@fee,@remark)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@security_day_account_id", MySqlDbType.Int32,11),
					new MySqlParameter("@trade_date", MySqlDbType.DateTime),
					new MySqlParameter("@trade_type", MySqlDbType.VarChar,10),
					new MySqlParameter("@stock_name", MySqlDbType.VarChar,20),
					new MySqlParameter("@stock_code", MySqlDbType.Int32,11),
					new MySqlParameter("@price", MySqlDbType.Float),
					new MySqlParameter("@num", MySqlDbType.Int32,11),
					new MySqlParameter("@fee", MySqlDbType.Float),
					new MySqlParameter("@remark", MySqlDbType.VarChar,100)};
			parameters[0].Value = security_day_account_id;
			parameters[1].Value = trade_date;
			parameters[2].Value = trade_type;
			parameters[3].Value = stock_name;
			parameters[4].Value = stock_code;
			parameters[5].Value = price;
			parameters[6].Value = num;
			parameters[7].Value = fee;
			parameters[8].Value = remark;

			int line = DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
            if (line > 0) return true;
            return false;
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update `stock_day_count` set ");
			strSql.Append("`security_day_account_id`=@security_day_account_id,");
			strSql.Append("`trade_date`=@trade_date,");
			strSql.Append("`trade_type`=@trade_type,");
			strSql.Append("`stock_name`=@stock_name,");
			strSql.Append("`stock_code`=@stock_code,");
			strSql.Append("`price`=@price,");
			strSql.Append("`num`=@num,");
			strSql.Append("`fee`=@fee,");
			strSql.Append("`remark`=@remark");
			strSql.Append(" where `id`=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@security_day_account_id", MySqlDbType.Int32,11),
					new MySqlParameter("@trade_date", MySqlDbType.DateTime),
					new MySqlParameter("@trade_type", MySqlDbType.VarChar,10),
					new MySqlParameter("@stock_name", MySqlDbType.VarChar,20),
					new MySqlParameter("@stock_code", MySqlDbType.Int32,11),
					new MySqlParameter("@price", MySqlDbType.Float),
					new MySqlParameter("@num", MySqlDbType.Int32,11),
					new MySqlParameter("@fee", MySqlDbType.Float),
					new MySqlParameter("@remark", MySqlDbType.VarChar,100),
					new MySqlParameter("@id", MySqlDbType.Int32,11)};
			parameters[0].Value = security_day_account_id;
			parameters[1].Value = trade_date;
			parameters[2].Value = trade_type;
			parameters[3].Value = stock_name;
			parameters[4].Value = stock_code;
			parameters[5].Value = price;
			parameters[6].Value = num;
			parameters[7].Value = fee;
			parameters[8].Value = remark;
			parameters[9].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from `stock_day_count` ");
			strSql.Append(" where `id`=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)};
			parameters[0].Value = id;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select `id`,`security_day_account_id`,`trade_date`,`trade_type`,`stock_name`,`stock_code`,`price`,`num`,`fee`,`remark` ");
			strSql.Append(" FROM `stock_day_count` ");
			strSql.Append(" where `id`=@id ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id", MySqlDbType.Int32)};
			parameters[0].Value = id;

			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["id"]!=null && ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					this.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["security_day_account_id"]!=null && ds.Tables[0].Rows[0]["security_day_account_id"].ToString()!="")
				{
					this.security_day_account_id=int.Parse(ds.Tables[0].Rows[0]["security_day_account_id"].ToString());
				}
				if(ds.Tables[0].Rows[0]["trade_date"]!=null && ds.Tables[0].Rows[0]["trade_date"].ToString()!="")
				{
					this.trade_date=DateTime.Parse(ds.Tables[0].Rows[0]["trade_date"].ToString());
				}
				if(ds.Tables[0].Rows[0]["trade_type"]!=null )
				{
					this.trade_type=ds.Tables[0].Rows[0]["trade_type"].ToString();
				}
				if(ds.Tables[0].Rows[0]["stock_name"]!=null )
				{
					this.stock_name=ds.Tables[0].Rows[0]["stock_name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["stock_code"]!=null && ds.Tables[0].Rows[0]["stock_code"].ToString()!="")
				{
					this.stock_code=int.Parse(ds.Tables[0].Rows[0]["stock_code"].ToString());
				}
				if(ds.Tables[0].Rows[0]["price"]!=null && ds.Tables[0].Rows[0]["price"].ToString()!="")
				{
					this.price=float.Parse(ds.Tables[0].Rows[0]["price"].ToString());
				}
				if(ds.Tables[0].Rows[0]["num"]!=null && ds.Tables[0].Rows[0]["num"].ToString()!="")
				{
					this.num=int.Parse(ds.Tables[0].Rows[0]["num"].ToString());
				}
				if(ds.Tables[0].Rows[0]["fee"]!=null && ds.Tables[0].Rows[0]["fee"].ToString()!="")
				{
					this.fee=float.Parse(ds.Tables[0].Rows[0]["fee"].ToString());
				}
				if(ds.Tables[0].Rows[0]["remark"]!=null )
				{
					this.remark=ds.Tables[0].Rows[0]["remark"].ToString();
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM `stock_day_count` ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

